﻿#region License
//  Distrubted Under the GNU Public License version 2 (GPLv2)
// ========================================
// 
//  QuizzMasterStudio Version 3 
//  Copyright © 2012 , The Sparks (Autism App Jam 2014)
//  All rights reserved.  
// 
// Robert Long, Zephyr Yao, Hillary Chansavang, Li Xiao, Arial Xiao
// 
//  This program is free software: you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation, either version 3 of the License, or
//  (at your option) any later version.
//  
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//  
//  You should have received a copy of the GNU General Public License
//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
//  The full license is also included in the root folder.
// 
// Robert Long
//  Email: rbtLong@live.com
#endregion

using System;
using System.Windows.Media.Animation;
using Core.RandomMovements;

namespace Core.Avatar.ViewModel
{
    public enum GestureStatus { Running = 0, Stopped }
    public class TurtleVM
    {
        private readonly EyeDirectionGesture _eyeAnim;
        private readonly ArmGestures _armsAnim;
        private GestureStatus _gesturesStatus = GestureStatus.Stopped;
        private readonly Storyboard[] _talkingAnim;
        private EyeDirectionGesture _eyeDirectionGesture;
        private ArmGestures _armGestures;
        private Storyboard[] _storyboard;
        private readonly Storyboard _waveHello;

        public GestureStatus GesturesStatus { get { return _gesturesStatus; } }

        public TurtleVM(EyeDirectionGesture eyeAnim, 
            ArmGestures armAnim, Storyboard[] talkingAnim,
            Storyboard waveHello)
        {
            _eyeAnim = eyeAnim;
            _armsAnim = armAnim;
            _talkingAnim = talkingAnim;
            _waveHello = waveHello;
        }

        public void StartGestures()
        {
            if (_gesturesStatus != GestureStatus.Running)
            {
                _gesturesStatus = GestureStatus.Running;
                _eyeAnim.Start();
                _armsAnim.Start();
            }
        }

        public void StopGestures()
        {
            if (_gesturesStatus != GestureStatus.Stopped)
            {
                _gesturesStatus = GestureStatus.Stopped;
                _eyeAnim.Stop();
                _armsAnim.Stop();
            }
        }

        public void SpeakGesture()
        {
            int n = new Random().Next(0, _talkingAnim.Length-1);
            _talkingAnim[n].AutoReverse = true;
            _talkingAnim[n].Begin();
        }

        public void WaveHelloGesture()
        {
            _waveHello.Begin();
        }
    }
}
